<?php

/**
 * Index.php
 * Niushop商城系统 - 团队十年电商经验汇集巨献!
 * =========================================================
 * Copy right 2015-2025 山西牛酷信息科技有限公司, 保留所有权利。
 * ----------------------------------------------
 * 官方网址: http://www.niushop.com.cn
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和使用。
 * 任何企业和个人不允许对程序代码以任何形式任何目的再发布。
 * =========================================================
 * @author : niuteam
 * @date : 2015.1.17
 * @version : v1.0.0.0
 */

namespace app\api\controller;

use app\model\goods\Goods as GoodsModel;
use app\model\goods\GoodsBrand as GoodsBrandModel;
use app\model\system\Floor;
use app\model\web\Pc as PcModel;

/**
 * Pc端接口
 * @author Administrator
 *
 */
class Pc extends BaseApi
{
	/**
	 * 获取热门搜索关键词
	 */
	public function hotSearchWords()
	{
		$pc_model = new PcModel();
		$info = $pc_model->getHotSearchWords();
		return $this->response($this->success($info[ 'data' ][ 'value' ]));
	}

	/**
	 * 获取默认搜索关键词
	 */
	public function defaultSearchWords()
	{
		$pc_model = new PcModel();
		$info = $pc_model->getDefaultSearchWords();
		return $this->response($this->success($info[ 'data' ][ 'value' ]));
	}

	/**
	 * 获取首页浮层
	 */
	public function floatLayer()
	{
		$pc_model = new PcModel();
		$info = $pc_model->getFloatLayer();
		return $this->response($this->success($info[ 'data' ][ 'value' ]));
	}

	/**
	 * 楼层列表
	 *
	 * @return string
	 */
	public function floors()
	{
		$site_id = input('site_id', 0);
		$list = ( new Floor )->getFloorList($site_id, 1);
		if (!empty($list[ 'data' ][ 'list' ])) {
			$goods = new GoodsModel();
			$goods_brand_model = new GoodsBrandModel();
			foreach ($list[ 'data' ][ 'list' ] as $k => $v) {
				if (!empty($v)) {
					$json = $v[ 'config' ];
					if (!empty($json)) {
						$json = json_decode($json, true);
//						$json = json_decode('{"index":{"type":"text","value":{"text":"1F","link":""}},"leftLeftImage":{"type":"img","value":{"url":"upload/common/images/20200709/20200709034730159428085005764.png","link":""}},"leftRightBrands":{"type":"brand","value":{"brand_ids":"62,63,64,65,66","list":[]}},"rightCargos":{"type":"goods","value":{"sku_ids":"758,757,750","list":[]}}}', true);
						foreach ($json as $ck => $cv) {
							if (!empty($cv[ 'type' ])) {
								if ($cv[ 'type' ] == 'goods') {
									$field = 'goods_id,sku_id,sku_name,price,market_price,discount_price,stock,sale_num,sku_image,goods_name,site_id,website_id,is_own,is_free_shipping,introduction,promotion_type';
									$order = 'sort desc,create_time desc';
									$goods_sku_list = $goods->getGoodsSkuList([ [ 'sku_id', 'in', $cv[ 'value' ][ 'sku_ids' ] ] ], $field, $order);
									$goods_sku_list = $goods_sku_list[ 'data' ];
									$json[ $ck ][ 'value' ][ 'list' ] = $goods_sku_list;
								} elseif ($cv[ 'type' ] == 'brand') {
									$condition = [
										[ 'brand_id', 'in', $cv[ 'value' ][ 'brand_ids' ] ]
									];
									$brand_list = $goods_brand_model->getBrandList($condition, 'brand_id, brand_name, brand_initial,site_id, image_url', 'sort desc,create_time desc');
									$brand_list = $brand_list[ 'data' ];
									$json[ $ck ][ 'value' ][ 'list' ] = $brand_list;
								}
							}
						}
						$list[ 'data' ][ 'list' ][ $k ][ 'config' ] = $json;
					}
				}
			}
		}
		return $this->response($list);
	}

	/**
	 * 获取导航
	 */
	public function navList()
	{
		$pc_model = new PcModel();
		$data = $pc_model->getNavPageList([ [ 'is_show', '=', 1 ] ], 1, 0, 'sort');
		return $this->response($data);
	}

	/**
	 * 获取友情链接
	 */
	public function friendlyLink()
	{
		$pc_model = new PcModel();
		$data = $pc_model->getlinkPageList([ [ 'is_show', '=', 1 ] ], 1, 0, 'link_sort');
		return $this->response($data);
	}
}
